package com.info.zhiduoduo.repository.mapper.maker;

import com.baomidou.mybatisplus.mapper.BaseMapper;
import com.info.zhiduoduo.repository.dto.maker.MakerAlipayPrincipalFlowDto;
import com.info.zhiduoduo.repository.entity.maker.MakerAlipayPrincipalFlow;

import org.apache.ibatis.annotations.Select;

import java.util.Date;
import java.util.List;

/**
 * <p>
 *  Mapper 接口
 * </p>
 *
 * @author bob
 * @since 2021-07-11
 */
public interface MakerAlipayPrincipalFlowMapper extends BaseMapper<MakerAlipayPrincipalFlow> {

	@Select(" select epi.compname,pf.*,pri.name as principalName,sm.managername as adminName,project_type," +
			" bm.business_manager as merchandiserName,zbm.business_manager as corporateConsultant " +
			" from zdd_maker_alipay_principal_flow pf " +
			" left join zdd_system_manager sm on sm.managerid = pf.adminid " +
			" left join zdd_maker_alipay_principal pri on pf.principal_id = pri.id" +
			" left join (" +
			"   SELECT compid,compname,transfer_no,project_type from zdd_entrustment_project_item where transfer_no is not null group by import_id,transfer_no " +
			" ) epi on pf.order_no = epi.transfer_no " +
			" LEFT JOIN zdd_company_account ca ON epi.compid = ca.compid   " +
			" LEFT JOIN zdd_business_manager bm ON  ca.merchandiser_id = bm.business_manager_id  " +
			" left join zdd_business_manager zbm on zbm.business_manager_id = ca.business_manager_id"+
			" where if(isnull(#{type}) or #{type}='',pf.type in (1,3,4,5), pf.type in(0${type})) " +
			" and CONCAT(pri.name,pf.order_no,pf.remark) like '%${name}%'" +
			" and if(isnull(#{compname}), 1=1, epi.compname like '%${compname}%') " +
			" and if(isnull(#{from}), 1=1, pf.flow_time >= #{from})" +
			" and if(isnull(#{to}), 1=1, pf.flow_time <= #{to}) " +
			" order by pf.id desc ")
	List<MakerAlipayPrincipalFlowDto> list(String name,String compname,String type, Date from, Date to);
}
